/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_orm.htm
 *
 * Zhiqim Orm is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.orm.test;

import java.util.ArrayList;
import java.util.List;

import org.zhiqim.kernel.Global;
import org.zhiqim.kernel.Zhiqim;
import org.zhiqim.orm.ORMConstants;
import org.zhiqim.orm.ORMParameter;
import org.zhiqim.orm.ORMServer;


public class ORMBoot implements ORMConstants
{
    public static void loadBin()
    {
        List<String> pathList = new ArrayList<>();
        pathList.add("./bin");
        Zhiqim.loadClassAliasName(pathList);
    }
    
    public static void initMySQLServer() throws Exception
    {
        loadBin();
        
        ORMParameter parameter = new ORMParameter();
        parameter.setDbType("mysql");
        parameter.setDriver("org.zhiqim.mysql5_1_47.jdbc.Driver");
        parameter.setUrl("jdbc:mysql://172.16.11.210:3306/zhiqim_orm?useUnicode=true&amp;characterEncoding=UTF-8");
        parameter.setUser("root");
        parameter.setPass("root");
        parameter.setMinPoolSize(5);
        parameter.setMaxPoolSize(200);
        parameter.setMaxKeepTime(7000);
        parameter.setUpdateSqlLog(true);
        parameter.setQuerySqlLog(true);
        
        ORMServer server = new ORMServer();
        server.setId("orm");
        server.create(parameter);
        
        Global.addService(server);
    }
    
    public static void initOracleServer() throws Exception
    {
        loadBin();
        
        ORMParameter parameter = new ORMParameter();
        parameter.setDbType("oracle");
        parameter.setDriver("oracle.jdbc.driver.OracleDriver");
        parameter.setUrl("jdbc:oracle:thin:@127.0.0.1:1521:ORCL");
        parameter.setUser("zhiqim");
        parameter.setPass("zhiqim");
        parameter.setUpdateSqlLog(true);
        parameter.setQuerySqlLog(true);
        
        ORMServer server = new ORMServer();
        server.setId("orm");
        server.create(parameter);
        
        Global.addService(server);
    }
    
    public static void initMSSQLServer() throws Exception
    {
        loadBin();
        
        ORMParameter parameter = new ORMParameter();
        parameter.setDbType("mssql");
        parameter.setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        parameter.setUrl("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=zhiqim_orm_test");
        parameter.setUser("sa");
        parameter.setPass("taobug2012");
        parameter.setUpdateSqlLog(true);
        parameter.setQuerySqlLog(true);
        
        ORMServer server = new ORMServer();
        server.setId("orm");
        server.create(parameter);
        
        Global.addService(server);
    }
    
    public static void initPSQLServer() throws Exception
    {
        loadBin();
        
        ORMParameter parameter = new ORMParameter();
        parameter.setDbType("postgresql");
        parameter.setDriver("org.postgresql.Driver");
        parameter.setUrl("jdbc:postgresql://127.0.0.1:5432/zhiqim_orm_test");
        parameter.setUser("postgres");
        parameter.setPass("taobug2012");
        parameter.setUpdateSqlLog(true);
        parameter.setQuerySqlLog(true);
        
        ORMServer server = new ORMServer();
        server.setId("orm");
        server.create(parameter);
        
        Global.addService(server);
    }

    public static void initSQLiteServer() throws Exception
    {
        loadBin();
        
        ORMParameter parameter = new ORMParameter();
        parameter.setDbType("sqlite");
        parameter.setDriver("org.sqlite.JDBC");
        parameter.setUrl("jdbc:sqlite:./database/zhiqim_orm_test.db");
        parameter.setUser("root");
        parameter.setPass("root");
        parameter.setMinPoolSize(5);
        parameter.setMaxPoolSize(200);
        parameter.setMaxKeepTime(7000);
        parameter.setUpdateSqlLog(true);
        parameter.setQuerySqlLog(true);
        
        ORMServer server = new ORMServer();
        server.setId("orm");
        server.create(parameter);
        
        Global.addService(server);
    }
}
